from tests.rypark_background.get_cookie import *
from common.config import *
import requests


class Pay:
    # =====================大运营后台交易信息=====================
    # 大运营后台查询交易汇总数据
    # billTypes=账单类型（0：线上支付，1：无感支付）
    # sources=来源（0：微信，1：支付宝，2：服务台）
    def internal_pay_sum(self, env, startDate, endDate,
                         parkName=None, billTypes=None, sources=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/billReport"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"parkName": parkName,
                "billTypes": billTypes,
                "sources": sources,
                "startDate": startDate,
                "endDate": endDate}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营后台查询交易汇总数据导出
    def internal_pay_sum_export(self, env, startDate=None, endDate=None,
                                parkName=None, billTypes=None, sources=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/billReportExport"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"parkName": parkName,
                "billTypes": billTypes,
                "sources": sources,
                "startDate": startDate,
                "endDate": endDate}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营后台交易明细
    # billTypeList=订单类型集合（0：线上支付，1：无感支付）
    # entryStart=入场开始时间 yyyy-MM-dd HH:mm:ss
    # paySatrt=支付开始时间 yyyy-MM-dd HH:mm:ss
    # payNo=流水号
    # payTypeList=支付方式（0:仅微信 1： 仅支付宝 2:仅卡券 3：仅积分
    # 4：微信+卡券 5： 微信+积分 6 支付宝+卡券
    # 7：支付宝+积分 8：卡券+积分 9：微信+卡券+积分 10 ： 支付宝+卡券+积分）
    # plateno=车牌号
    # sourceList=订单来源（0：微信，1：支付宝， 2：服务台）
    def internal_pay_list(self, env,
                          billNo=None, billTypeList=None, entryStart=None,
                          entryEnd=None, parkName=None, paySatrt=None,
                          payEnd=None, payNo=None, payTypeList=None,
                          plateno=None, sourceList=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/billListPage"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"billNo": billNo,
                "billTypeList": billTypeList,
                "entryStart": entryStart,
                "entryEnd": entryEnd,
                "parkName": parkName,
                "paySatrt": paySatrt,
                "payEnd": payEnd,
                "payNo": payNo,
                "payTypeList": payTypeList,
                "plateno": plateno,
                "sourceList": sourceList}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营后台交易明细导出
    def internal_pay_list_export(self, env, entryStart=None, entryEnd=None,
                                 billNo=None, billTypeList=None, parkName=None,
                                 paySatrt=None, payEnd=None, payNo=None,
                                 payTypeList=None, plateno=None, sourceList=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/exportBillListDetail"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"billNo": billNo,
                "billTypeList": billTypeList,
                "entryStart": entryStart,
                "entryEnd": entryEnd,
                "parkName": parkName,
                "paySatrt": paySatrt,
                "payEnd": payEnd,
                "payNo": payNo,
                "payTypeList": payTypeList,
                "plateno": plateno,
                "sourceList": sourceList}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营后台交易详情
    def internal_pay_detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/billListPage"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"id": id}
        return requests.post(url, headers=headers, json=dict).json()

    # =====================商户后台交易信息=====================
    # 商户后台查询交易汇总数据
    # billTypes=账单类型（0：线上支付，1：无感支付）
    # sources=来源（0：微信，1：支付宝，2：服务台）
    def shop_pay_sum(self, env, startDate, endDate,
                     billTypes=None, sources=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/businessBillReport"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"billTypes": billTypes,
                "sources": sources,
                "startDate": startDate,
                "endDate": endDate}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台查询交易汇总数据导出
    def shop_pay_sum_export(self, env, startDate=None, endDate=None,
                            billTypes=None, sources=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/businessBillReportExport"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"billTypes": billTypes,
                "sources": sources,
                "startDate": startDate,
                "endDate": endDate}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台交易明细
    # billTypeList=订单类型集合（0：线上支付，1：无感支付）
    # entryStart=入场开始时间 yyyy-MM-dd HH:mm:ss
    # paySatrt=支付开始时间 yyyy-MM-dd HH:mm:ss
    # payTypeList=支付方式（0:仅微信 1： 仅支付宝 2:仅卡券 3：仅积分
    # 4：微信+卡券 5： 微信+积分 6 支付宝+卡券
    # 7：支付宝+积分 8：卡券+积分 9：微信+卡券+积分 10 ： 支付宝+卡券+积分）
    # plateno=车牌号
    # sourceList=订单来源（0：微信，1：支付宝， 2：服务台）
    def shop_pay_list(self, env, billNo=None,
                      billTypeList=None, entryStart=None, entryEnd=None,
                      parkName=None, paySatrt=None, payEnd=None,
                      payTypeList=None, plateno=None, sourceList=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/bsBillListPage"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"billNo": billNo,
                "billTypeList": billTypeList,
                "entryStart": entryStart,
                "entryEnd": entryEnd,
                "parkName": parkName,
                "paySatrt": paySatrt,
                "payEnd": payEnd,
                "payTypeList": payTypeList,
                "plateno": plateno,
                "sourceList": sourceList}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台交易明细导出
    def shop_pay_list_export(self, env, entryStart=None, entryEnd=None,
                             billNo=None, billTypeList=None, parkName=None,
                             paySatrt=None, payEnd=None, payTypeList=None,
                             plateno=None, sourceList=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/bsExportBillListDetail"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"billNo": billNo,
                "billTypeList": billTypeList,
                "entryStart": entryStart,
                "entryEnd": entryEnd,
                "parkName": parkName,
                "paySatrt": paySatrt,
                "payEnd": payEnd,
                "payTypeList": payTypeList,
                "plateno": plateno,
                "sourceList": sourceList}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台交易详情
    def shop_pay_detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkBill/bsBillListDetail"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"id": id}
        return requests.post(url, headers=headers, json=dict).json()
